/**
 * @author David Culyba
 * @see edu/cmu/cs/stage3/alice/authoringtool/AuthoringTool.java
 * 
 */

package edu.cmu.cs.stage3.alice.authoringtool.dialog;

import edu.cmu.cs.stage3.resourceBundle.I18n;

public class ErrorContentPane extends AliceAlertContentPane {

 public final static int LESS_DETAIL_MODE = 0;
 public final static int MORE_DETAIL_MODE = 1;

 protected Throwable throwable;

 public ErrorContentPane () {
  super();
  }

 //Rem @Override
 public void preDialogShow (javax.swing.JDialog dialog) {
  super.preDialogShow( dialog );
  writeAliceHeaderToTextPane();
  writeThrowableToTextPane();
  }

 //Rem @Override
 public String getTitle () {
  return I18n.getString("errorContentTitle"); // "iVProg - Error"
  }

 public void setThrowable (Throwable t) {
  throwable = t;
  }

 protected void writeThrowableToTextPane () {
  if (throwable != null) {
   detailStream.println( "Throwable that caused the error:" );
   throwable.printStackTrace( detailStream );
   if (throwable instanceof edu.cmu.cs.stage3.alice.core.ExceptionWrapper) {
    edu.cmu.cs.stage3.alice.core.ExceptionWrapper ew = (edu.cmu.cs.stage3.alice.core.ExceptionWrapper)throwable;
    Exception e = ew.getWrappedException();
    detailStream.println( "Wrapped exception:" );
    e.printStackTrace( detailStream );
    }
  } else {
   new Exception("No throwable given. Here's the stack trace:").printStackTrace(detailStream);
   }
  detailStream.println();
  }

 }
